﻿//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")

/**
*    @file:    main.cpp
*    @brief:
*    @author:  sanshi522@163.com
*    @date:    2025-02-19  18:02
*/
#include "autorestarter.h"
#include "widget.h"

#include <QApplication>
#include <QMessageBox>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // 检查命令行参数数量
    if (argc != 3) {
        QMessageBox::critical(nullptr,"警告","参数缺失，请传入等待时长以及程序路径");
        return -1;
    }

    // 解析命令行参数
    bool ok;
    int waitTime = QString(argv[1]).toInt(&ok);
    if (!ok || waitTime <= 0) {
        QMessageBox::critical(nullptr,"警告","无效的等待参数，请传入大于0的等待时长参数，单位：s");
        return -1;
    }

    QString programPath = QString::fromLocal8Bit(argv[2]);
    if (programPath.isEmpty()) {
        QMessageBox::critical(nullptr,"警告","无效的进程路径，请传入准确的程序路径。");
        return -1;
    }

    // 初始化并启动自动重启器
    AutoRestarter restarter(waitTime, programPath);
    restarter.start();

    return app.exec();
}
